home *** CD-ROM | disk | FTP | other *** search
- /* DeathRoids Source!
- *
- * I hope you aren't expecting too many comments, because there are
- * practically none. If you have trouble figuring anything out,
- * drop me a message.
- *
- * All of the file loading routines have right over them the
- * original file names, so just switch the comments to use those.
- *
- *********************************************************
- * NOTICE: PERMISION TO USE AND/OR MODIFY THIS SOURCE
- * CODE IS HEREBY GRANTED BY THE AUTHOR PROVIDED THAT
- * NO FEE IS CHARGED FOR THIS PRODUCT OR ANY PRODUCT THAT
- * USES DIRECT SOURCE FROM THIS PRODUCT. NEITHER ARE
- * ANY OR ALL OF THE GRAPHICS IMAGES TO BE USED IN
- * COMMERCIAL PRODUCTS WITHOUT THE EXPRESS CONSENT OF
- * THE AUTHOR.
- *
- * (Basically, this is free, so keep it that way :)
- *********************************************************
- *
- * Note: Written in BC++ 3.1, so I use both "//" and "/*" for
- * commenting. Also, Tab size is 3.
- * The project file consists of "asteroid.c", "sound.c",
- * "dmalib.c" and "timerx.c" These other files are part
- * of the SOUNDX sound system, which can be found on
- * "x2ftp.oulu.fi" in the "/pub/msdos/programming/music"
- * directory.
- *
- * TAB SIZE: 3
- *
- */
-
- #include <stdlib.h>
- #include <stdio.h>
- #include <conio.h>
- #include <stdio.h>
- #include <math.h>
- #include <bios.h>
- #include <time.h>
- #include <stddef.h>
- #include <dos.h>
- #include <io.h>
- #include <fcntl.h>
- #include <alloc.h>
- #include <malloc.h>
- #include <sys\stat.h>
- #include "mydef.h"
- #include "sound.h"
- #include "timerx.h"
- #include "dmalib.h"
-
- extern volatile BYTE voc_mode;
-
- char huge *loadsound(char *filename);
-
- unsigned char pal[768];
-
- #define TSENG '1'
- #define TRIDENT '2'
- #define ATI '3'
- #define VESA '4'
- char graphics_chip;
- int ati_index;
- unsigned char ReadWin, WriteWin;
-
- // speed delay for faster computers
- int buldelay, rockdelay;
-
- // for accessing the registers for using interrupts
- union REGS regs;
- struct SREGS sregs;
-
- // for detecting key-presses
- #define PRESSED 1
- #define UNPRESSED 0
-
- #define MAXBUL 20 // max number of bullets on screen
- #define MAXROCK 20 // max number of rocks on screen
- //#define MAXSPEED 6
- #define MAXSPEED 6291456
- //#define MAXSPEED 10291456
-
- #define ROCK_DELAY_RATE 2
-
- // total number of pictures for each type of object
- #define NUM_SHIP_PICS 40
- #define NUM_ROCK_PICS 22
- #define NUM_BUL_PICS 25
-
- //#define NUM_ROCK_PICS 5
-
- // Maximum / minimum screen coordinates for objects
- //#define MAX_WIN_X 960
- #define MAX_WIN_X 990
- #define MIN_WIN_X 35
- #define MAX_WIN_Y 715
- #define MIN_WIN_Y 35
-
- // number of stars in the background
- #define NUMSTARS 150
-
- // So I don't have to use floats, I shift (multiply) integers.
- #define FSCALE 1048576 // Float -> Integer scale
- #define FSHIFT 20 // 2^20 = 1048576
-
- // number of degrees the player turns each time they press left or right
- #define TURNRATE 3
-
- // These are macros for speed, so I don't have to call another
- // function. Note that graphics_chip is always VESA, but since
- // that wouldn't slow this down *too* much, I didn't bother to
- // change it.
- #define putpixel(x,y,col) *((char far *)0xA0000000+x+(y<<10))=col
- #define SetWriteBank(bank) \
- if (graphics_chip == TSENG) \
- outportb(0x3CD,bank); \
- else if (graphics_chip == TRIDENT) \
- outport(0x3C4,((bank^2)<<8)+0x0E); \
- else if (graphics_chip == ATI) \
- { \
- outportb(ati_index,0xB2); \
- outportb(ati_index+1,bank<<1); \
- } \
- else if (graphics_chip == VESA) \
- { \
- regs.x.ax = 0x4F05; \
- regs.h.bh = 0x00; \
- regs.h.bl = WriteWin; \
- regs.x.dx = bank; \
- int86(0x10,®s,®s); \
- }
- #define SetReadBank(bank) \
- if (graphics_chip == TSENG) \
- outportb(0x3CD,(bank)<<4); \
- else if (graphics_chip == TRIDENT) \
- outport(0x3C4,(bank<<8)+0x0E); \
- else if (graphics_chip == ATI) \
- { \
- outportb(ati_index,0xB2); \
- outportb(ati_index+1,bank<<5); \
- } \
- else if (graphics_chip == VESA) \
- { \
- regs.x.ax = 0x4F05; \
- regs.h.bh = 0x00; \
- regs.h.bl = ReadWin; \
- regs.x.dx = bank; \
- int86(0x10,®s,®s); \
- }
-
- // outportb(ati_index+1,(inportb(ati_index+1)&0xE1)|(bank << 1)); \
- // outportb(ati_index+1,(inportb(ati_index+1)&0xE1)|(bank << 1)); \
-
- #define SHIP_SIZE 52
- #define ROCK_LG_SIZE 52
- #define ROCK_MD_SIZE 40
- #define ROCK_SM_SIZE 28
- #define BUL_SIZE 16
-
- struct star_type
- {
- int x,y;
- char col;
- } star[NUMSTARS];
-
- // Very convenient types: boolean flags, status flags, and rock sizes
- typedef enum { off = 0, on = 1 } flag;
- //typedef enum { dieing = -1, inactive = 0, active = 1 } statflag;
- #define dieing -1
- #define inactive 0
- #define active 1
- typedef enum { small = 1, med = 2, large = 3 } sizetype;
-
- //double dsint[360]; // degrees sin() table: FAST!!
- //double dcost[360]; // degrees cos() table: FAST!!
- long int dsint[360];
- long int dcost[360];
-
- int level;
-
- struct bultype // Standard bullet type
- {
- // float x,y;
- int x,y;
- // float dx,dy; // (x,y) coords, (dx,dy) movement
- long int dx, dy;
- int lcount; // lifespan counter
- short int curframe; // current animation frame number
- // statflag status; // Active / Inactive flag
- short int status;
- } bul[MAXBUL]; // Global bull def. May be moved to
- // shiptype def. if multiple player!
-
- struct player_shiptype // Standard player-ship type
- {
- // float x,y;
- int x,y;
- // float dx,dy; // (x,y) coords, (dx,dy) movement
- long int dx,dy;
- int dir; // current direction (degrees)
- int shield; // shield strength
- long int score; // score
- short int lives; // number of lives
- flag trishot,mgun, // triple-shot, machine gun flags
- luck,retros, // luck, retro-rocket flags
- autoshld,bomb, // auto-shield, bomb flags
- longshot; // extra bul length flag
- // statflag status; // Active (alive) / Inactive / dieing. :)
- short int status;
- } player; // global def - change to array if > 1 plyr.
-
- struct rocktype // Standard rock type
- {
- // float x,y;
- int x,y;
- // float dx,dy; // (x,y) coords, (dx,dy) movement
- long int dx, dy;
- short int curframe; // current animation frame number
- short int framedelay;
- // statflag status; // Active / Inactive / exploding flag
- short int status;
- sizetype size; // size of rock
- } rock[MAXROCK]; // Global rock def.
-
- void drawobject(signed char far object[],int x,int y);
- void drawshields(int shields);
-
- // Homemade printf routine for graphics screens
- void Alpha(char s[], int x, int y);
- // for the Alpha() functions
- void PutLetter (int l, int x, int y);
-
- // The definition of each character for the Alpha() function
- signed char aa[30] = {0,1,1,1,0,-2,1,1,0,0,1,-2,1,1,1,1,1,-2,1,1,0,0,1,-2,1,1,0,0,1,-3 };
- signed char bb[30] = {1,1,1,1,0,-2,1,1,0,0,1,-2,1,1,1,1,0,-2,1,1,0,0,1,-2,1,1,1,1,0,-3 };
- signed char cc[30] = {1,1,1,1,1,-2,1,0,0,0,0,-2,1,1,0,0,0,-2,1,1,0,0,0,-2,1,1,1,1,1,-3 };
- signed char dd[30] = {1,1,1,1,0,-2,1,0,0,0,1,-2,1,1,0,0,1,-2,1,1,0,0,1,-2,1,1,1,1,0,-3 };
- signed char ee[30] = {1,1,1,1,1,-2,1,0,0,0,0,-2,1,1,1,1,0,-2,1,1,0,0,0,-2,1,1,1,1,1,-3 };
- signed char ff[30] = {1,1,1,1,1,-2,1,0,0,0,0,-2,1,1,1,1,0,-2,1,1,0,0,0,-2,1,1,0,0,0,-3 };
- signed char gg[30] = {1,1,1,1,1,-2,1,0,0,0,0,-2,1,0,0,1,1,-2,1,1,0,0,1,-2,1,1,1,1,1,-3 };
- signed char hh[30] = {1,0,0,1,1,-2,1,0,0,1,1,-2,1,1,1,1,1,-2,1,1,0,0,1,-2,1,1,0,0,1,-3 };
- signed char ii[30] = {1,1,1,1,1,-2,0,0,1,0,0,-2,0,0,1,0,0,-2,0,0,1,1,0,-2,1,1,1,1,1,-3 };
- signed char jj[30] = {1,1,1,1,1,-2,0,0,0,1,0,-2,0,0,0,1,0,-2,1,1,0,1,0,-2,1,1,1,1,0,-3 };
- signed char kk[30] = {1,0,0,0,1,-2,1,0,0,1,0,-2,1,1,1,0,0,-2,1,1,0,1,0,-2,1,1,0,0,1,-3 };
- signed char ll[30] = {1,0,0,0,0,-2,1,0,0,0,0,-2,1,1,0,0,0,-2,1,1,0,0,1,-2,1,1,1,1,1,-3 };
- signed char mm[30] = {1,0,0,0,1,-2,1,1,0,1,1,-2,1,1,1,1,1,-2,1,0,1,0,1,-2,1,0,1,0,1,-3 };
- signed char nn[30] = {1,0,0,0,1,-2,1,1,0,0,1,-2,1,1,1,1,1,-2,1,0,1,1,1,-2,1,0,0,1,1,-3 };
- signed char oo[30] = {0,1,1,1,0,-2,1,0,0,0,1,-2,1,0,0,0,1,-2,1,1,0,0,1,-2,0,1,1,1,0,-3 };
- signed char pp[30] = {1,1,1,1,0,-2,1,0,0,1,1,-2,1,1,1,1,0,-2,1,1,0,0,0,-2,1,1,0,0,0,-3 };
- signed char qq[30] = {0,1,1,1,0,-2,1,0,0,0,1,-2,1,0,0,0,1,-2,1,1,0,1,0,-2,0,1,1,0,1,-3 };
- signed char rr[30] = {1,1,1,1,0,-2,1,0,0,0,1,-2,1,1,1,1,0,-2,1,1,0,0,1,-2,1,1,0,0,1,-3 };
- signed char ss[30] = {0,1,1,1,1,-2,1,0,0,0,0,-2,1,1,1,1,1,-2,0,0,0,0,1,-2,1,1,1,1,0,-3 };
- signed char tt[30] = {1,1,1,1,1,-2,0,0,1,0,0,-2,0,0,1,0,0,-2,0,1,1,0,0,-2,0,1,1,0,0,-3 };
- signed char uu[30] = {1,0,0,0,1,-2,1,0,0,0,1,-2,1,1,0,0,1,-2,1,1,0,0,1,-2,1,1,1,1,1,-3 };
- signed char vv[30] = {1,0,0,0,1,-2,1,0,0,0,1,-2,1,1,0,0,1,-2,0,1,0,1,0,-2,0,0,1,0,0,-3 };
- signed char ww[30] = {1,0,0,0,1,-2,1,0,1,0,1,-2,1,0,1,0,1,-2,1,1,1,1,1,-2,0,1,1,1,0,-3 };
- signed char xx[30] = {1,0,0,0,1,-2,1,1,0,1,1,-2,0,0,1,0,0,-2,1,1,0,1,1,-2,1,0,0,0,1,-3 };
- signed char yy[30] = {0,1,0,1,0,-2,1,1,0,1,1,-2,1,1,1,1,1,-2,0,0,1,0,0,-2,0,0,1,0,0,-3 };
- signed char zz[30] = {1,1,1,1,1,-2,1,0,0,1,1,-2,0,0,1,0,0,-2,1,1,0,0,1,-2,1,1,1,1,1,-3 };
-
- signed char n1[30] = {0,1,1,1,0,-2,1,1,1,1,0,-2,0,0,1,1,0,-2,0,0,1,1,0,-2,1,1,1,1,1,-3 };
- signed char n2[30] = {1,1,1,1,1,-2,0,0,0,1,1,-2,0,1,1,1,1,-2,1,1,0,0,0,-2,1,1,1,1,1,-3 };
- signed char n3[30] = {1,1,1,1,1,-2,0,0,0,0,1,-2,0,1,1,1,1,-2,0,0,0,1,1,-2,1,1,1,1,1,-3 };
- signed char n4[30] = {1,0,1,1,0,-2,1,0,1,1,0,-2,1,1,1,1,1,-2,0,0,1,1,0,-2,0,0,1,1,0,-3 };
- signed char n5[30] = {1,1,1,1,1,-2,1,1,0,0,0,-2,1,1,1,1,0,-2,0,0,0,1,1,-2,1,1,1,1,1,-3 };
- signed char n6[30] = {1,1,1,1,1,-2,1,1,0,0,0,-2,1,1,1,1,1,-2,1,1,0,0,1,-2,1,1,1,1,1,-3 };
- signed char n7[30] = {1,1,1,1,1,-2,1,0,0,1,1,-2,0,0,0,1,1,-2,0,0,0,1,1,-2,0,0,0,1,1,-3 };
- signed char n8[30] = {1,1,1,1,1,-2,1,0,0,0,1,-2,1,1,1,1,1,-2,1,1,0,0,1,-2,1,1,1,1,1,-3 };
- signed char n9[30] = {1,1,1,1,1,-2,1,0,0,1,1,-2,1,1,1,1,1,-2,0,0,0,1,1,-2,0,0,0,1,1,-3 };
- signed char n0[30] = {1,1,1,1,1,-2,1,0,0,0,1,-2,1,0,0,0,1,-2,1,1,0,0,1,-2,1,1,1,1,1,-3 };
-
- signed char col[30]= {0,0,0,0,0,-2,0,0,1,0,0,-2,0,0,0,0,0,-2,0,0,1,0,0,-2,0,0,0,0,0,-3 };
- signed char spc[30]= {0,0,0,0,0,-2,0,0,0,0,0,-2,0,0,0,0,0,-2,0,0,0,0,0,-2,0,0,0,0,0,-3 };
-
- signed char exc[30]= {0,1,0,1,0,-2,
- 0,1,0,1,0,-2,
- 0,1,0,1,0,-2,
- 0,0,0,0,0,-2,
- 0,1,0,1,0,-3 };
- signed char prd[30]= {0,0,0,0,0,-2,
- 0,0,0,0,0,-2,
- 0,0,0,0,0,-2,
- 0,0,1,1,0,-2,
- 0,0,1,1,0,-3 };
- signed char dsh[30]= {0,0,0,0,0,-2,
- 0,0,0,0,0,-2,
- 0,1,1,1,0,-2,
- 0,0,0,0,0,-2,
- 0,0,0,0,0,-3 };
- signed char lpar[30]={0,0,0,1,0,-2,
- 0,0,1,0,0,-2,
- 0,0,1,0,0,-2,
- 0,0,1,0,0,-2,
- 0,0,0,1,0,-3 };
- signed char rpar[30]={0,1,0,0,0,-2,
- 0,0,1,0,0,-2,
- 0,0,1,0,0,-2,
- 0,0,1,0,0,-2,
- 0,1,0,0,0,-3 };
- signed char lbrk[30]={0,1,1,1,0,-2,
- 0,1,0,0,0,-2,
- 0,1,0,0,0,-2,
- 0,1,0,0,0,-2,
- 0,1,1,1,0,-3 };
- signed char rbrk[30]={0,1,1,1,0,-2,
- 0,0,0,1,0,-2,
- 0,0,0,1,0,-2,
- 0,0,0,1,0,-2,
- 0,1,1,1,0,-3 };
- signed char starc[30]={0,0,1,0,0,-2,
- 0,1,1,1,0,-2,
- 1,1,1,1,1,-2,
- 0,1,1,1,0,-2,
- 0,0,1,0,0,-3 };
- signed char coma[30]={0,0,0,0,0,-2,
- 0,0,0,0,0,-2,
- 0,0,1,0,0,-2,
- 0,0,1,0,0,-2,
- 0,1,0,0,0,-3 };
- signed char ques[30]={0,1,1,1,0,-2,
- 1,0,0,0,1,-2,
- 0,0,1,1,0,-2,
- 0,0,0,0,0,-2,
- 0,0,1,0,0,-3 };
- signed char hapy[30]={0,1,0,1,0,-2,
- 0,0,0,0,0,-2,
- 0,0,1,0,0,-2,
- 1,0,0,0,1,-2,
- 0,1,1,1,0,-3 };
- signed char quot[30]={0,1,0,1,0,-2,
- 0,1,0,1,0,-2,
- 0,0,0,0,0,-2,
- 0,0,0,0,0,-2,
- 0,0,0,0,0,-3 };
- signed char apos[30]={0,0,1,0,0,-2,
- 0,0,1,0,0,-2,
- 0,0,0,0,0,-2,
- 0,0,0,0,0,-2,
- 0,0,0,0,0,-3 };
- signed char ampr[30]={0,1,1,0,0,-2,
- 1,0,0,1,0,-2,
- 1,0,1,0,0,-2,
- 1,0,0,0,1,-2,
- 0,1,1,1,0,-3 };
-
- // Here's all my graphics pointers
- void far *ship_noshld_pic[NUM_SHIP_PICS];
- void far *aster_pic[NUM_ROCK_PICS];
- void far *ship_shld_pic[NUM_SHIP_PICS];
-
- void far *med_aster_pic[NUM_ROCK_PICS];
- void far *small_aster_pic[NUM_ROCK_PICS];
-
- void far *bullet_pic[NUM_BUL_PICS];
-
- void Init_Graphics(void);
- void Init_Sound(void);
- void MovePlayer(void);
- void CheckPlayer(void);
- void DrawPlayer(void);
- void ErasePlayer(void);
- void MoveRock(short int rocknum);
- void CheckRock(short int rocknum);
- void DrawRock(short int rocknum);
- void EraseRock(short int rocknum);
- void MoveBul(short int bulnum);
- void CheckBul(short int bulnum);
- void DrawBul(short int bulnum);
- void EraseBul(short int bulnum);
- void CalcNewLevel(void);
- void drawscreen(void);
- void NewRock(int x, int y, sizetype size);
- void KillRock(short int rocknum);
- void Init_Game(void);
- void DoKeys(void);
- void De_Init_Sound(void);
- void De_Init_Graphics(void);
-
- void Setup_Key_Interrupt(void);
- void Enable_Key_Interrupt(void);
- void Disable_Key_Interrupt(void);
-
- // Detects keypresses
- void interrupt lookkey();
-
- void bar(int x1, int y1, int x2, int y2);
- void rect(int x1, int y1, int x2, int y2);
- void cleardevice(void);
-
- void getimage(void far *pic_ptr,int x1,int y1, int size);
- void putimage(void far *pic_ptr,int x,int y, int size);
- void eraseimage(void far *pic_ptr, int x, int y, int size);
-
- void putpixel2(int x, int y, long color);
-
- char getpixel(int x, int y);
- long getpixel2(int x, int y);
-
- void chkkey(void);
-
- int display_raw(int x, int y, char *filename, int xsize, int ysize);
- void loadpics(void);
-
- void DrawStar(void);
- void set_intro_pal(void);
- int DoMenu(void);
- void draw_menu(void);
- void instruct(void);
-
- void DeathScreen(void);
- void NewLevel(void);
-
- // just for compatibility with Borland's graphics lib and
- // usuability for those of us who are used to it.
- #define setfillstyle(a,b) cur_color = b;
- #define setcolor(col_num) cur_color = col_num;
-
- // current color
- unsigned char cur_color;
- flag sound_mode = on;
-
- // various sounds in the game
- #define BEGIN 0
- #define FIRE 1
- #define HITROCK 2
- #define DIE 3
- #define QUIT 4
- #define MAXSND 5
- // Here's the sounds pointer, named soundb because something else
- // was already named "sound"
- char huge *soundb[MAXSND];
-
- struct KEY_INT // Key interrupt structure
- {
- int right; // key to turn right pressed / unpressed
-
- int left; // key to turn left pressed / unpressed
- int thrust; // key to thrust pressed / unpressed
- int esc; // key to quit pressed / unpressed
- int fire; // key to fire pressed / unpressed
- int shield; // key to raise shields pressed / unpressed
- int pause; // key to pause pressed / unpressed
- } k; // Global def.
-
- struct Key_Selections // user key selections - contains key codes...
- {
- int left_press;
- int left_unpress;
- int right_press;
- int right_unpress;
- int thrust_press;
- int thrust_unpress;
- int fire_press;
- int fire_unpress;
- int shield_press;
- int shield_unpress;
- } keyOpt; // Global def. - changed only in Options menu
- // Options menu never added
-
- struct address {
- char far *p;
- } temp;
-
- struct address far *addr = (struct address far *) 36;
- struct address far *int9 = (struct address far *) 240;
-
- void main()
- {
- int Quit = 0,i,j,num,complete;
- char out[100];
- /*
- printf("\nPlease enter graphics card:\n 1. Tseng ET4000 (Works!)\n");
- printf(" 2. Trident 8900 (doesn't work)\n");
- printf(" 3. ATI Graphics Ultra Mega Super Plus Pro (doesn't work)\n");
- printf(" 4. *NEW!* VESA graphics adaptor! :)\n");
- printf("\nWell? What'll it be? ");
- graphics_chip = getche();
- */
- /*
- I've disabled support for specific chip sets and rather decided to
- support only VESA.
- */
-
- graphics_chip = VESA;
- printf("\n\nDo you want sound? (Y/N) ");
-
- switch (getche())
- {
- case 'Y':
- case 'y': sound_mode = on; break;
- case 'N':
- case 'n': sound_mode = off; break;
- }
-
- printf("\n\nEnter BULLET delay factor? (0 = default) > ");
- scanf("%d",&buldelay);
- printf("\nEnter ROCK delay factor? (0 = default) > ");
- scanf("%d",&rockdelay);
-
- if (buldelay == 0)
- buldelay = 128;
- if (rockdelay == 0)
- rockdelay = 1024;
-
- Init_Graphics();
- Init_Sound();
-
- Setup_Key_Interrupt();
-
-
- // main loop
- while (Quit != 1)
- {
- // go to the menu -- when they come back, they are either
- // playing or quitting.
- Quit = DoMenu();
-
- if (Quit != 1)
- {
- Enable_Key_Interrupt();
-
- Init_Game();
-
- if (sound_mode == on)
- VocPlay((char far *)soundb[BEGIN]);
-
- k.esc = UNPRESSED;
- k.fire = UNPRESSED;
-
- while (k.esc != PRESSED)
- {
- complete = 0;
- while (!complete && k.esc != PRESSED)
- {
- for (i = 0; i < MAXBUL; i++)
- {
- if (bul[i].status == active)
- MoveBul(i);
- else
- {
- DrawStar();
- for (j = 0; j < (MAXROCK-i)*buldelay;j++);
- }
- }
-
- complete = 1;
- for (i = 0; i < MAXROCK; i++)
- {
- if (rock[i].status == active)
- {
- MoveRock(i);
- complete = 0;
- }
- else
- {
- DrawStar();
- for (j = 0; j < (MAXROCK-i)*rockdelay;j++);
- }
- }
-
- MovePlayer();
-
- DoKeys();
-
- drawscreen();
-
- if (player.status == dieing)
- {
- if (player.lives == 0)
- k.esc = PRESSED;
- else
- {
- for (i = 0; i < MAXROCK; i++)
- if (rock[i].status == active)
- {
- EraseRock(i);
- }
- for (i = 0; i < MAXBUL; i++)
- {
- EraseBul(i);
- bul[i].status = inactive;
- }
-
- ErasePlayer();
-
- player.shield = 200;
- player.lives -= 1;
- player.trishot = off; player.autoshld = off;
- player.mgun = off; player.bomb = off;
- player.luck = off; player.longshot = off;
- player.retros = off;
-
- player.x = (MAX_WIN_X + MIN_WIN_Y) >> 1;
- player.y = (MAX_WIN_Y + MIN_WIN_Y) >> 1;
- player.dx = 0;
- player.dy = 0;
- player.status = active;
- player.dir = 0;
-
- SetWriteBank(11);
- sprintf(out,"Score: %6ld Bonus: %6ld Lives: %2i Shields:"
- ,(long)player.score,(long)5000,player.lives);
- Alpha(out,0,0);
-
- DrawPlayer();
-
- for (i = 0; i < MAXROCK; i++)
- if (rock[i].status == active)
- DrawRock(i);
- }
- }
- }
- if (complete)
- NewLevel();
- else if (player.status == dieing)
- DeathScreen();
- }
-
- Disable_Key_Interrupt();
- }
- }
-
- De_Init_Sound();
- De_Init_Graphics();
-
- exit(0);
- }
-
- // Because we don't bother picking up the background when we draw
- // our sprites, the stars are going to be wiped out. To fix this,
- // instead of putting in more delay loops, we simply redraw the stars
- // whenever we have extra time. This function draws on star each
- // time it is called, then draws the next on the next time.
- void DrawStar(void)
- {
- static int i = 0;
-
- // outport(0x3CD,star[i].y>>6);
- SetWriteBank(star[i].y>>6);
-
- putpixel(star[i].x, star[i].y,star[i].col);
-
- if (++i >= NUMSTARS)
- i = 0;
- }
-
- void DeathScreen(void)
- {
- char out[50];
- union REGS regs;
- struct SREGS sregs;
-
- cleardevice();
- regs.x.ax = 0x1012;
- regs.x.bx = 0;
- regs.x.cx = 255;
-
- regs.x.dx = FP_OFF( (int far *)&pal[0] );
- sregs.es = FP_SEG( (int far *)&pal[0] );
-
- int86x(0x10, ®s, ®s, &sregs);
-
- SetWriteBank(5);
- sprintf(out,"Ooops! You died! Bummer, eh?");
- Alpha(out,30,2);
- sprintf(out,"Final Score: %ld",player.score);
- Alpha(out,30,4);
- SetWriteBank(6);
- sprintf(out,"[Press *FIRE* to return to main menu]");
- Alpha(out,27,2);
-
- while (k.fire != PRESSED)
- {}
-
- return;
- }
-
- void NewLevel(void)
- {
- int i;
- union REGS regs;
- struct SREGS sregs;
-
- char out[50];
-
- cleardevice();
- regs.x.ax = 0x1012;
- regs.x.bx = 0;
- regs.x.cx = 255;
-
- regs.x.dx = FP_OFF( (int far *)&pal[0] );
- sregs.es = FP_SEG( (int far *)&pal[0] );
-
- int86x(0x10, ®s, ®s, &sregs);
-
- SetWriteBank(5);
- sprintf(out,"Level %i completed!",level);
- Alpha(out,35,2);
- sprintf(out,"Bonus: %ld",(long)0);
- Alpha(out,35,3);
- sprintf(out,"Score: %ld",player.score);
- Alpha(out,35,5);
-
- SetWriteBank(6);
- sprintf(out,"[Press *FIRE* to begin next level]");
- Alpha(out,25,2);
-
- while (k.fire != PRESSED)
- {}
-
- cleardevice();
- regs.x.ax = 0x1012;
- regs.x.bx = 0;
- regs.x.cx = 255;
-
- regs.x.dx = FP_OFF( (int far *)&pal[0] );
- sregs.es = FP_SEG( (int far *)&pal[0] );
-
- int86x(0x10, ®s, ®s, &sregs);
-
- level++;
-
- CalcNewLevel();
-
- for (i = 0; i < MAXBUL; i++)
- bul[i].status = inactive;
-
- SetWriteBank(11);
-
- for (i = 16; i < 1040; i++)
- {
- putpixel(i,46,12);
- putpixel(i,47,13);
- putpixel(i,48,12);
- }
-
- sprintf(out,"Score: %6ld Bonus: %6ld Lives: %2i Shields:"
- ,(long)player.score,(long)5000,player.lives);
- Alpha(out,0,0);
-
- drawscreen();
-
- DrawPlayer();
- for (i = 0; i < MAXROCK; i++)
- if (rock[i].status == active)
- DrawRock(i);
-
- return;
- }
-
- int DoMenu(void)
- {
- char key = 0;
-
- while (kbhit())
- getch();
-
- draw_menu();
-
- while (key != 27)
- {
- key = getch();
- switch (key)
- {
- case 27 :
- case 'q' :
- case 'Q' :
- return(1);
- break;
- case 'p' :
- case 'P' :
- return(0);
- break;
- case 'i' :
- case 'I' :
- instruct();
- draw_menu();
- break;
- }
- }
- return(1);
- }
-
- void instruct(void)
- {
- char text[1000];
-
- cleardevice();
-
- set_intro_pal();
-
- SetWriteBank(2);
- sprintf(text,"INSTRUCTIONS:\n\n\
- These are pretty simple since this is the first release\n\
- (but *NOT* final!) of this game! Here they are:\n\n");
- Alpha(text,10,2);
- SetWriteBank(3);
- sprintf(text," Keypad 4 (left-arrow) rotates counter-clockwise.\n\
- Keypad 6 (right-arrow) rotates clockwise.\n\
- Keypad 8 (up-arrow) thrusts.\n\
- [LEFT-SHIFT] raises shields.\n");
- Alpha(text,10,2);
- SetWriteBank(4);
- sprintf(text," [CTRL] fires your Mega-Nuko-Death-O-Plenty-Blasters.\n\n\
- Collect little floaty things to gain more items such as: (not working)\n");
- Alpha(text,10,2);
-
- SetWriteBank(5);
- sprintf(text," Rapid-Fire Auto-Shields Triple-Shot\n\
- Retro-Rockets Long-Shot Luck\n\
- and Mega-Bombs!\n\
- Have Fun!");
- Alpha(text,10,2);
-
- SetWriteBank(7);
- sprintf(text,"NOTE: This game is *FREEWARE*! Public Domain.\n\
- You may distribute this game to anyone on the planet as long as you\n\
- don't charge them a cent.");
- Alpha(text,10,2);
-
- SetWriteBank(8);
- sprintf(text,"Feedback on this game is welcome! Anything from\n\
- \"This game is *GREAt*\" to \"This is the worst game I've played\n\
- in my entire life!\" Money wouldn't be refused either. %");
- Alpha(text,10,2);
-
- SetWriteBank(9);
- sprintf(text,"I may be reached at:\n\
- Augusto Roman\n\
- 4865 Las Alturas\n\
- Las Cruces, NM, 88011");
- Alpha(text,10,2);
-
- SetWriteBank(10);
- sprintf(text,"or via e-mail at: aroman@dante.nmsu.edu\n\n\
- % C SOURCE CODE AVAILABLE UPON REQUEST! %");
- Alpha(text,10,2);
-
- getch();
- }
-
- void draw_menu(void)
- {
- int i;
- unsigned char pal2[768];
- unsigned char out[100];
-
- union REGS regs;
- struct SREGS sregs;
-
- FILE *in_file;
-
- cleardevice();
-
- for (i = 0; i < 768; i++)
- pal2[i] = 0;
-
- regs.x.ax = 0x1012;
- regs.x.bx = 0;
- regs.x.cx = 255;
-
- regs.x.dx = FP_OFF( (int far *)&pal2[0] );
- sregs.es = FP_SEG( (int far *)&pal2[0] );
-
- int86x(0x10, ®s, ®s, &sregs);
-
- // display_raw(192,184,"intro1.raw",320,200);
- display_raw(192,184,"fil012.dat",320,200);
- // display_raw(512,184,"intro2.raw",320,200);
- display_raw(512,184,"fil013.dat",320,200);
- // display_raw(192,384,"intro3.raw",320,200);
- display_raw(192,384,"fil014.dat",320,200);
- // display_raw(512,384,"intro4.raw",320,200);
- display_raw(512,384,"fil015.dat",320,200);
-
- set_intro_pal();
-
- setcolor(192);
- rect(350,655,550,705);
-
- SetWriteBank(0);
- for (i = 0; i < 1024; i++)
- putpixel(i,5,192);
- for (i = 0; i < 1024; i++)
- putpixel(i,40,192);
- sprintf(out," DeathRoids!!\n Ver. 0.99b\n\nBy Augusto Roman");
- Alpha(out,33,2);
-
- SetWriteBank(10);
- sprintf(out,"P)lay new game!\nI)instructions\nQ)uit");
- Alpha(out,30,3);
-
- return;
- }
-
- void set_intro_pal(void)
- {
- int i;
- union REGS regs;
- struct SREGS sregs;
- char pal2[768];
-
- FILE *in_file;
-
- // in_file = fopen("intro.pal","rb");
- in_file = fopen("fil016.dat","rb");
- for (i = 0; i < 768; i++)
- pal2[i] = getc(in_file);
- fclose(in_file);
-
- for (i = 192; i < 224; i++)
- {
- pal2[i*3 ] = 63;
- pal2[i*3+1] = (i - 192)*2;
- pal2[i*3+2] = 0;
- }
- for (i = 224; i < 250; i++)
- {
- pal2[i*3 ] = 63 - (i - 224)*2;
- pal2[i*3+1] = 63;
- pal2[i*3+2] = 0;
- }
-
- pal2[0] = pal2[1] = pal2[2] = 0;
- pal2[11*3 ] = 0;
- pal2[11*3+1] = 63;
- pal2[11*3+2] = 0;
-
- regs.x.ax = 0x1012;
- regs.x.bx = 0;
- regs.x.cx = 255;
-
- regs.x.dx = FP_OFF( (int far *)&pal2[0] );
- sregs.es = FP_SEG( (int far *)&pal2[0] );
-
- int86x(0x10, ®s, ®s, &sregs);
-
- return;
- }
-
- /*
- int getkey(void)
- {
- int key, lo, hi;
-
- key = bioskey(0);
- lo = key & 0X00FF;
- hi = (key & 0XFF00) >> 8;
- return((lo == 0) ? hi + 256 : lo);
- }
-
-
- void chkkey(void)
- {
- int ch;
- ch = bioskey(0);
- ch = (ch & 0x00FF) == 0 ? (ch & 0xFF00) + 256 : (ch & 0x00FF);
-
- k.thrust = k.left = k.right = k.fire = k.shield = UNPRESSED;
-
- if (ch == 328)
- k.thrust = PRESSED;
- else if (ch == 331)
- k.left = PRESSED;
- else if (ch == 333)
- k.right = PRESSED;
- else if (ch == 'z' || ch == 'Z')
- k.fire = PRESSED;
- else
- k.shield = PRESSED;
- }
- */
- void Thrust(void)
- {
- player.dx += dcost[player.dir];
- player.dy += dsint[player.dir];
-
- if (player.dx > MAXSPEED)
- // player.dx = MAXSPEED;
- player.dx -= dcost[player.dir];
- else if (player.dx < -MAXSPEED)
- // player.dx = -MAXSPEED;
- player.dx -= dcost[player.dir];
- if (player.dy > MAXSPEED)
- // player.dy = MAXSPEED;
- player.dy -= dsint[player.dir];
- else if (player.dy < -MAXSPEED)
- // player.dy = -MAXSPEED;
- player.dy -= dsint[player.dir];
-
- if (player.retros == on)
- {
- player.dx -= player.dx >> 2;
- player.dy -= player.dy >> 2;
- }
-
- return;
- }
-
- void MovePlayer(void)
- {
- static int shld_flag = UNPRESSED;
-
- if (shld_flag == PRESSED)
- eraseimage(ship_shld_pic[player.dir / 9],player.x-32,player.y-32, SHIP_SIZE);
- else
- eraseimage(ship_noshld_pic[player.dir / 9],player.x-32,player.y-32, SHIP_SIZE);
-
- if (k.left == PRESSED) /* turn left */
- if ( ( player.dir -= TURNRATE ) < 0)
- player.dir += 360;
-
- if (k.right == PRESSED) /* turn right */
- if ( ( player.dir += TURNRATE ) >= 360)
- player.dir -= 360;
-
- player.x += player.dx >> FSHIFT;
- player.y += player.dy >> FSHIFT;
-
- CheckPlayer();
-
- if (player.shield > 0)
- shld_flag = k.shield;
- else
- {
- shld_flag = UNPRESSED;
- k.shield = UNPRESSED;
- }
-
- if (shld_flag == PRESSED)
- putimage(ship_shld_pic[player.dir / 9],player.x-32,player.y-32, SHIP_SIZE);
- else
- putimage(ship_noshld_pic[player.dir / 9],player.x-32,player.y-32, SHIP_SIZE);
-
- return;
- }
-
- void ErasePlayer(void)
- {
- if (k.shield == PRESSED)
- eraseimage(ship_shld_pic[player.dir / 9],player.x-32,player.y-32, SHIP_SIZE);
- else
- eraseimage(ship_noshld_pic[player.dir / 9],player.x-32,player.y-32, SHIP_SIZE);
- return;
- }
-
- void DrawPlayer(void)
- {
- if (k.shield == PRESSED)
- putimage(ship_shld_pic[player.dir / 9],player.x-32,player.y-32, SHIP_SIZE);
- else
- putimage(ship_noshld_pic[player.dir / 9],player.x-32,player.y-32, SHIP_SIZE);
-
- return;
- }
-
- void MoveRock(short int rocknum)
- {
- EraseRock(rocknum);
- // DrawRock(rocknum);
-
- rock[rocknum].x += rock[rocknum].dx >> FSHIFT;
- rock[rocknum].y += rock[rocknum].dy >> FSHIFT;
-
- CheckRock(rocknum);
-
- if (rock[rocknum].status == active)
- DrawRock(rocknum);
-
- return;
- }
-
- void MoveBul(short int bulnum)
- {
- EraseBul(bulnum);
- // DrawBul(bulnum);
-
- CheckBul(bulnum);
-
- bul[bulnum].x += bul[bulnum].dx >> FSHIFT;
- bul[bulnum].y += bul[bulnum].dy >> FSHIFT;
-
- DrawBul(bulnum);
- }
-
- void CheckPlayer(void)
- {
- if (player.x > MAX_WIN_X)
- player.x = MIN_WIN_X;
- else if (player.x < MIN_WIN_X)
- player.x = MAX_WIN_X;
- if (player.y > MAX_WIN_Y)
- player.y = MIN_WIN_Y;
- else if (player.y < MIN_WIN_Y)
- player.y = MAX_WIN_Y;
-
- return;
- }
-
- void CheckRock(short int rocknum)
- {
- short int radius;
-
- switch (rock[rocknum].size)
- {
- case large:
- radius = 45;
- break;
- case med:
- radius = 40;
- break;
- case small:
- radius = 35;
- break;
- }
-
- if (rock[rocknum].status != active)
- return;
-
- if (rock[rocknum].x > MAX_WIN_X)
- rock[rocknum].x = MIN_WIN_X;
- else if (rock[rocknum].x < MIN_WIN_X)
- rock[rocknum].x = MAX_WIN_X;
- if (rock[rocknum].y > MAX_WIN_Y)
- rock[rocknum].y = MIN_WIN_Y;
- else if (rock[rocknum].y < MIN_WIN_Y)
- rock[rocknum].y = MAX_WIN_Y;
-
- if (abs(rock[rocknum].x - player.x) < radius)
- if (abs(rock[rocknum].y - player.y) < radius)
- {
- if (k.shield == PRESSED && player.shield > 0)
- {
- if (sound_mode == on)
- {
- VocStop();
- VocPlay((char far *)soundb[HITROCK]);
- }
- KillRock(rocknum);
- rock[rocknum].status = inactive;
- // EraseRock(rocknum);
- // DrawRock(rocknum);
- }
- else
- {
- if (sound_mode == on)
- {
- VocStop();
- VocPlay((char far *)soundb[DIE]);
- }
- player.status = dieing;
- DrawRock(rocknum);
- // gotoxy(1,1);
- // printf("*** HIT BY ROCK #%3d - [%3.2f,%3.2f], status: %3d\n ",
- // rocknum, rock[rocknum].x, rock[rocknum].y,
- // rock[rocknum].status);
- }
- }
-
- if (rock[rocknum].framedelay++ >= ROCK_DELAY_RATE)
- {
- if (++rock[rocknum].curframe >= NUM_ROCK_PICS )
- rock[rocknum].curframe = 0;
- rock[rocknum].framedelay = 0;
- }
-
- return;
- }
-
- void CheckBul(short int bulnum)
- {
- int i;
-
- if (bul[bulnum].lcount++ > 50)
- {
- bul[bulnum].status = inactive;
- return;
- }
-
- for (i = 0; i < MAXROCK; i++)
- {
- if (rock[i].status == active)
- if (abs(bul[bulnum].x - rock[i].x) < (8 << rock[i].size)+2)
- if (abs(bul[bulnum].y - rock[i].y) < (8 << rock[i].size)+2)
- {
- if (sound_mode == on)
- {
- VocStop();
- VocPlay((char far *)soundb[HITROCK]);
- }
- KillRock(i);
- rock[i].status = inactive;
- bul[bulnum].status = inactive;
- EraseBul(bulnum);
- // EraseRock(i);
- // DrawBul(bulnum);
- // DrawRock(i);
- player.score += 250 * rock[i].size;
- break;
- }
- }
-
- if (bul[bulnum].x > MAX_WIN_X)
- bul[bulnum].x = MIN_WIN_X;
- else if (bul[bulnum].x < MIN_WIN_X)
- bul[bulnum].x = MAX_WIN_X;
- if (bul[bulnum].y > MAX_WIN_Y)
- bul[bulnum].y = MIN_WIN_Y;
- else if (bul[bulnum].y < MIN_WIN_Y)
- bul[bulnum].y = MAX_WIN_Y;
-
- if (++bul[bulnum].curframe >= NUM_BUL_PICS)
- bul[bulnum].curframe = 0;
-
- return;
- }
-
- void FireBul(void)
- {
- int i;
-
- for (i = 0; i < MAXBUL; i++)
- if (bul[i].status == inactive)
- {
- bul[i].dx = player.dx + 6*dcost[player.dir];
- bul[i].dy = player.dy + 6*dsint[player.dir];
- bul[i].x = player.x + ((3*dcost[player.dir])>>FSHIFT);
- bul[i].y = player.y + ((3*dsint[player.dir])>>FSHIFT);
- bul[i].lcount = 0;
- bul[i].status = active;
- bul[i].curframe = 0;
- DrawBul(i);
- if (sound_mode == on)
- {
- VocStop();
- VocPlay((char far *)soundb[FIRE]);
- }
- break;
- }
-
- return;
- }
-
- void NewRock(int x, int y, sizetype size)
- {
- int i;
-
- for (i = 0; i < MAXROCK; i++)
- if (rock[i].status == inactive)
- {
- rock[i].x = x;
- rock[i].y = y;
- rock[i].dx = ((random(10000)-5000) / 1000)*FSCALE;
- rock[i].dy = ((random(10000)-5000) / 1000)*FSCALE;
- rock[i].size = size;
- rock[i].status = active;
- rock[i].curframe = random(NUM_ROCK_PICS);
- rock[i].framedelay = 0;
- DrawRock(i);
- break;
- }
- return;
- }
-
- void KillRock(short int rocknum)
- {
- int i;
-
- EraseRock(rocknum);
- // DrawRock(rocknum);
- rock[rocknum].status = dieing;
-
- if (rock[rocknum].size == small)
- return;
-
- for (i = 0; i < rock[rocknum].size; i++)
- NewRock(rock[rocknum].x, rock[rocknum].y, rock[rocknum].size-1);
-
- return;
- }
-
- void DoKeys(void)
- {
- static flag fire_flag = UNPRESSED;
- static int wep_wait = 0;
-
- /*** Weapon System ***/
-
- if ((fire_flag == UNPRESSED || player.mgun) && wep_wait++ > 2)
- if (k.fire == PRESSED)
- {
- FireBul();
- wep_wait = 0;
- fire_flag = PRESSED;
- }
- if (k.fire == UNPRESSED)
- fire_flag = UNPRESSED;
-
- if (wep_wait > 50)
- wep_wait = 50;
-
- /*** Ship Control ***/
-
- // if (k.left == PRESSED) /* turn left */
- // if ( ( player.dir -= TURNRATE ) < 0)
- // player.dir += 360;
-
- // if (k.right == PRESSED) /* turn right */
- // if ( ( player.dir += TURNRATE ) >= 360)
- // player.dir -= 360;
-
- if (k.thrust == PRESSED) /* thrust */
- Thrust();
-
- if (k.shield == PRESSED)
- {
- if (player.shield > 0)
- player.shield -= 2;
- else
- k.shield = UNPRESSED;
- }
-
- return;
- }
-
- void EraseBul(short int bulnum)
- {
-
- // putimage(bullet_back[bulnum],bul[bulnum].x-8,bul[bulnum].y-8,BUL_SIZE);
-
- eraseimage(bullet_pic[bul[bulnum].curframe],bul[bulnum].x-8,bul[bulnum].y-8,BUL_SIZE);
-
- return;
- }
-
- void DrawBul(short int bulnum)
- {
-
- // getimage(bullet_back[bulnum],bul[bulnum].x-8,bul[bulnum].y-8,16);
-
- if (bul[bulnum].status == active)
- putimage(bullet_pic[bul[bulnum].curframe],bul[bulnum].x-8,bul[bulnum].y-8,BUL_SIZE);
-
- return;
- }
-
- void EraseRock(short int rocknum)
- {
- switch (rock[rocknum].size)
- {
- case large:
- // putimage(aster_back[rocknum],rock[rocknum].x-32, rock[rocknum].y-32,ROCK_LG_SIZE);
- eraseimage(aster_pic[rock[rocknum].curframe],rock[rocknum].x-32, rock[rocknum].y-32,ROCK_LG_SIZE);
- break;
- case med:
- eraseimage(med_aster_pic[rock[rocknum].curframe],rock[rocknum].x-16, rock[rocknum].y-16,ROCK_MD_SIZE);
- break;
- case small:
- eraseimage(small_aster_pic[rock[rocknum].curframe],rock[rocknum].x-8, rock[rocknum].y-8,ROCK_SM_SIZE);
- break;
- }
-
- return;
- }
-
- void DrawRock(short int rocknum)
- {
- switch (rock[rocknum].size)
- {
- case large:
- // getimage(aster_back[rocknum],rock[rocknum].x-32, rock[rocknum].y-32,64);
- putimage(aster_pic[rock[rocknum].curframe],rock[rocknum].x-32, rock[rocknum].y-32,ROCK_LG_SIZE);
- break;
- case med:
- // getimage(aster_back[rocknum],rock[rocknum].x-16, rock[rocknum].y-16,32);
- putimage(med_aster_pic[rock[rocknum].curframe],rock[rocknum].x-16, rock[rocknum].y-16,ROCK_MD_SIZE);
- break;
- case small:
- // getimage(aster_back[rocknum],rock[rocknum].x-8, rock[rocknum].y-8,16);
- putimage(small_aster_pic[rock[rocknum].curframe],rock[rocknum].x-8, rock[rocknum].y-8,ROCK_SM_SIZE);
- break;
- }
-
- return;
- }
-
- void drawscreen(void)
- {
- // int i,j;
- char output[30];
- // unsigned long i;
-
- // outportb(0x3CD,750>>6);
- SetWriteBank(750>>6);
- /*
- for (i = 0; i < 1023; i++)
- {
- putpixel(i,750,22);
- putpixel(i,751,25);
- putpixel(i,752,22);
- }
- */
- // sprintf(output,"Score: %6ld Bonus: %6ld Lives: %2i Shields:"
- // ,(long)player.score,(long)5000,player.lives);
-
- sprintf(output,"%6ld",player.score);
- Alpha(output,7,0);
-
- sprintf(output,"%6ld",(long)5000);
- Alpha(output,22,0);
-
- // i = farcoreleft();
- // sprintf(output,"Core Left: %6ld",i);
- // Alpha(output,65,0);
-
- drawshields(player.shield);
-
- /*
- Alpha(output,0,0);
-
- sprintf(output,"Dir: %4i",player.dir);
-
- Alpha(output,70,0);
-
- drawshields(player.shield);
- */
- return;
- }
-
- void drawshields(int shields)
- {
- int i,j,col,temp;
-
- temp = shields + 604;
- col = shields/20+1;
-
- for (i = 604; i < temp; i += 2)
- for (j = 755; j < 765; j += 2)
- putpixel(i,j,col);
-
- for (i = i; i < 804; i += 2)
- for (j = 755; j < 765; j += 2)
- putpixel(i,j,14);
-
- return;
- }
-
- void Alpha(char s[], int x, int y)
- {
- int i, xoff = 0;
-
- i = -1;
- while (s[++i] != '\0')
- {
- if (s[i] > 96)
- s[i] -= 32;
- else if (s[i] == 10)
- {
- y++;
- xoff = -1;
- }
- PutLetter (s[i], x+xoff, y);
- xoff++;
- }
- return;
- }
-
-
- void PutLetter (int l, int x, int y)
- {
- switch (l)
- {
- case 32 : drawobject(spc,x,y); break;
- case 33 : drawobject(exc,x,y); break;
- case 34 : drawobject(quot,x,y); break;
- case 37 : drawobject(hapy,x,y); break;
- case 39 : drawobject(apos,x,y); break;
- case 40 : drawobject(lpar,x,y); break;
- case 41 : drawobject(rpar,x,y); break;
- case 42 : drawobject(starc,x,y); break;
- case 44 : drawobject(coma,x,y); break;
- case 45 : drawobject(dsh,x,y); break;
- case 46 : drawobject(prd,x,y); break;
- case 48 : drawobject(n0,x,y); break;
- case 49 : drawobject(n1,x,y); break;
- case 50 : drawobject(n2,x,y); break;
- case 51 : drawobject(n3,x,y); break;
- case 52 : drawobject(n4,x,y); break;
- case 53 : drawobject(n5,x,y); break;
- case 54 : drawobject(n6,x,y); break;
- case 55 : drawobject(n7,x,y); break;
- case 56 : drawobject(n8,x,y); break;
- case 57 : drawobject(n9,x,y); break;
- case 58 : drawobject(col,x,y); break;
- case 63 : drawobject(ques,x,y); break;
- case 64 : drawobject(ampr,x,y); break;
- case 65 : drawobject(aa,x,y); break;
- case 66 : drawobject(bb,x,y); break;
- case 67 : drawobject(cc,x,y); break;
- case 68 : drawobject(dd,x,y); break;
- case 69 : drawobject(ee,x,y); break;
- case 70 : drawobject(ff,x,y); break;
- case 71 : drawobject(gg,x,y); break;
- case 72 : drawobject(hh,x,y); break;
- case 73 : drawobject(ii,x,y); break;
- case 74 : drawobject(jj,x,y); break;
- case 75 : drawobject(kk,x,y); break;
- case 76 : drawobject(ll,x,y); break;
- case 77 : drawobject(mm,x,y); break;
- case 78 : drawobject(nn,x,y); break;
- case 79 : drawobject(oo,x,y); break;
- case 80 : drawobject(pp,x,y); break;
- case 81 : drawobject(qq,x,y); break;
- case 82 : drawobject(rr,x,y); break;
- case 83 : drawobject(ss,x,y); break;
- case 84 : drawobject(tt,x,y); break;
- case 85 : drawobject(uu,x,y); break;
- case 86 : drawobject(vv,x,y); break;
- case 87 : drawobject(ww,x,y); break;
- case 88 : drawobject(xx,x,y); break;
- case 89 : drawobject(yy,x,y); break;
- case 90 : drawobject(zz,x,y); break;
- case 91 : drawobject(lbrk,x,y); break;
- case 93 : drawobject(rbrk,x,y); break;
- default :
- break;
- }
- return;
- }
-
- void drawobject(signed char far object[],int x,int y)
- {
- int i = 0,j = 1;
-
- int sx, sy;
-
- sx = 4 + x * 12;
- sy = 755 + y * 12;
-
- do
- {
- if (object[i] == 0)
- // putpixel(sx+j*2,sy,120);
- putpixel(sx+j*2,sy,0);
- else if (object[i] == 1)
- // putpixel(sx+j*2,sy,48);
- putpixel(sx+j*2,sy,11);
- else if (object[i] == -2)
- {
- sy+=2;
- j = 0;
- }
- j++;
- i++;
- }
- while (object[i] != -3);
-
- return;
- }
-
- void Init_Game(void)
- {
- int i;
- double pi = 3.141592654;
- char output[50];
-
- union REGS regs;
- struct SREGS sregs;
-
- randomize();
-
- cleardevice();
-
- regs.x.ax = 0x1012;
- regs.x.bx = 0;
- regs.x.cx = 255;
- regs.x.dx = FP_OFF( (int far *)&pal[0] );
- sregs.es = FP_SEG( (int far *)&pal[0] );
- int86x(0x10, ®s, ®s, &sregs);
-
- for (i = 0; i < 360; i++)
- {
- dsint[i] = (sin((float)i*pi/180.0))*FSCALE;
- dcost[i] = (cos((float)i*pi/180.0))*FSCALE;
- }
-
- keyOpt.left_press = 75;
- keyOpt.left_unpress = 203;
- keyOpt.right_press = 77;
- keyOpt.right_unpress = 205;
- keyOpt.thrust_press = 72;
- keyOpt.thrust_unpress = 200;
- keyOpt.shield_press = 42;
- keyOpt.shield_unpress = 170;
- keyOpt.fire_press = 0;
- keyOpt.fire_unpress = 0;
-
- level = 1;
-
- player.shield = 200;
- player.lives = 3;
- player.score = 0;
- player.trishot = off; player.autoshld = off;
- player.mgun = off; player.bomb = off;
- player.luck = off; player.longshot = off;
- player.retros = off;
-
- CalcNewLevel();
-
- // outportb(0x3CD,750>>6);
- SetWriteBank(11);
-
- for (i = 16; i < 1040; i++)
- {
- putpixel(i,46,12);
- putpixel(i,47,13);
- putpixel(i,48,12);
- }
-
- sprintf(output,"Score: %6ld Bonus: %6ld Lives: %2i Shields:"
- ,(long)player.score,(long)5000,player.lives);
- Alpha(output,0,0);
-
- drawscreen();
-
- DrawPlayer();
- for (i = 0; i < MAXROCK; i++)
- if (rock[i].status == active)
- DrawRock(i);
-
- return;
- }
-
- void CalcNewLevel(void)
- {
- int i;
- int centerx, centery;
- int tempx, tempy;
- int numrocks;
-
- centerx = (MAX_WIN_X + MIN_WIN_Y) >> 1;
- centery = (MAX_WIN_Y + MIN_WIN_Y) >> 1;
- player.x = centerx;
- player.y = centery;
- player.dx = 0;
- player.dy = 0;
- player.status = active;
- player.dir = 0;
-
- numrocks = (level/2)+2;
-
- for (i = 0; i < MAXROCK; i++)
- rock[i].status = inactive;
-
- for (i = 0; i < MAXBUL; i++)
- bul[i].status = inactive;
-
- for (i = 0; i < numrocks; i++)
- {
- while (tempx > centerx-centerx*0.10 && tempx < centerx+centerx*0.10)
- tempx = random(MAX_WIN_X-MIN_WIN_X)+MIN_WIN_X;
-
- while (tempy > centery-centery*0.10 && tempy < centery+centery*0.10)
- tempy = random(MAX_WIN_Y-MIN_WIN_Y)+MIN_WIN_Y;
-
- NewRock(tempx,tempy,large);
- }
- }
-
- void bar(int x1, int y1, int x2, int y2)
- {
- int i,j;
- for (j = y1; j < y2; j++)
- for (i = x1; i < x2; i++)
- {
- // outportb(0x3CD,(j>>6));
- SetWriteBank(j>>6);
- putpixel(i,j,cur_color);
- }
- return;
- }
-
- char getpixel(int x, int y)
- {
- // outportb(0x3CD,((y>>6)<<4));
- SetReadBank(y>>6);
- return(*((char far *)0xA0000000+x+(y<<10)));
- }
-
- void rect(int x1, int y1, int x2, int y2)
- {
- int i, j;
- for (j = y1; j < y2; j++)
- {
- SetWriteBank(j >> 6);
- putpixel(x1,j,cur_color);
- putpixel(x2,j,cur_color);
- }
-
- SetWriteBank(y1>>6);
- for (i = x1; i < x2; i++)
- putpixel(i,y1,cur_color);
- SetWriteBank(y2>>6);
- for (i = x1; i < x2; i++)
- putpixel(i,y2,cur_color);
-
- return;
- }
-
- void Init_Graphics(void)
- {
- int i,j,x,y,col;
-
- int ship_offx, ship_offy;
- int rock_lg_offx, rock_lg_offy;
- int rock_md_offx, rock_md_offy;
- int rock_sm_offx, rock_sm_offy;
- int bul_offx, bul_offy;
-
- float angle;
- char out[10];
- long corenum;
-
- union REGS regs;
- struct SREGS sregs;
-
- cleardevice();
-
- loadpics();
-
- ship_offx = ship_offy = 0;
- bul_offx = 0;
- bul_offy = SHIP_SIZE*4;
- rock_lg_offx = 0;
- rock_lg_offy = bul_offy + BUL_SIZE*3;
- rock_md_offx = SHIP_SIZE*10;
- rock_md_offy = 0;
- rock_sm_offx = SHIP_SIZE*10;
- rock_sm_offy = ROCK_MD_SIZE*5;
-
- for (i = 0; i < NUM_SHIP_PICS; i++)
- {
- if ((ship_noshld_pic[i] = malloc(SHIP_SIZE*SHIP_SIZE)) == NULL)
- printf("WARNING: SHIP_NOSHLD[%3] is NULL\n",i);
- if ((ship_shld_pic[i] = malloc(SHIP_SIZE*SHIP_SIZE)) == NULL)
- printf("WARNING: SHIP_SHLD[%3] is NULL\n",i);
- }
- for (i = 0; i < NUM_ROCK_PICS; i++)
- {
- if ((aster_pic[i] = malloc(ROCK_LG_SIZE*ROCK_LG_SIZE)) == NULL)
- printf("WARNING: LARGE ROCK[%3] is NULL\n",i);
- if ((med_aster_pic[i] = malloc(ROCK_MD_SIZE*ROCK_MD_SIZE)) == NULL)
- printf("WARNING: MED ROCK[%3] is NULL\n",i);
- if ((small_aster_pic[i] = malloc(ROCK_SM_SIZE*ROCK_SM_SIZE)) == NULL)
- printf("WARNING: SMALL ROCK[%3] is NULL\n",i);
- }
- for (i = 0; i < NUM_BUL_PICS; i++)
- if ((bullet_pic[i] = malloc(BUL_SIZE*BUL_SIZE)) == NULL)
- printf("WARNING: BULLET[%3] is NULL\n",i);
-
- for (j = 0; j < 4; j++)
- for (i = 0; i < 10; i++)
- getimage(ship_noshld_pic[i+j*10],i*SHIP_SIZE,j*SHIP_SIZE,SHIP_SIZE);
-
- for (j = 0; j < 4; j++)
- for (i = 0; i < 10; i++)
- {
- for (angle = 0; angle < 6.28318530718; angle += 0.01)
- {
- x = 26*cos(angle) + i*SHIP_SIZE + SHIP_SIZE/2;
- y = 26*sin(angle) + j*SHIP_SIZE + SHIP_SIZE/2;
- SetWriteBank(y>>6);
- putpixel(x,y,2);
- }
- }
-
- for (j = 0; j < 4; j++)
- for (i = 0; i < 10; i++)
- getimage(ship_shld_pic[i+j*10],i*SHIP_SIZE,j*SHIP_SIZE,SHIP_SIZE);
-
- // setcolor(4);
- for (j = 0; j < 3; j++)
- for (i = 0; i < 10; i++)
- {
- if (i+j*10 >= NUM_BUL_PICS)
- break;
- getimage(bullet_pic[i+j*10],i*BUL_SIZE+bul_offx,
- j*BUL_SIZE+bul_offy,BUL_SIZE);
- // bar(i*BUL_SIZE+bul_offx,j*BUL_SIZE+bul_offy,
- // i*BUL_SIZE+bul_offx+BUL_SIZE,j*BUL_SIZE+bul_offy+BUL_SIZE);
- }
-
- for (j = 0; j < 5; j++)
- for (i = 0; i < 10; i+=2)
- {
- if ((i/2)+j*5 >= NUM_ROCK_PICS)
- break;
- getimage(aster_pic[(i/2)+j*5],i*ROCK_LG_SIZE+rock_lg_offx,
- j*ROCK_LG_SIZE+rock_lg_offy,ROCK_LG_SIZE);
- getimage(med_aster_pic[NUM_ROCK_PICS-((i/2)+j*5+1)],i*ROCK_MD_SIZE+rock_md_offx,
- // getimage(med_aster_pic[(i/2)+j*5],i*ROCK_MD_SIZE+rock_md_offx,
- j*ROCK_MD_SIZE+rock_md_offy,ROCK_MD_SIZE);
- getimage(small_aster_pic[(i/2)+j*5],i*ROCK_SM_SIZE+rock_sm_offx,
- j*ROCK_SM_SIZE+rock_sm_offy,ROCK_SM_SIZE);
- }
-
-
- // getch();
- /*
- i = 0;
- j = NUM_ROCK_PICS;
- col = 0;
- while (!col)
- {
- putimage(bullet_pic[i],768,512,BUL_SIZE);
- printf("ASTEROID %3i \r",i);
- out[0] = getch();
- eraseimage(bullet_pic[i],768,512,BUL_SIZE);
- if (out[0] == 'q' || out[0] == 'Q')
- col = 1;
- if (++i >= NUM_BUL_PICS)
- i = 0;
- }
-
- getch();
- exit(0);
- */
- /*
- for (i = 0; i < MAXROCK; i++)
- getimage(aster_back[i],512,0,ROCK_LG_SIZE);
- for (i = 0; i < MAXBUL; i++)
- getimage(bullet_back[i],512,0,BUL_SIZE);
- getimage(ship_back,512,0,SHIP_SIZE);
- */
- /*
- setcolor(52);
- bar(128,0,192,64);
-
- setcolor(44);
- bar(500,500,516,516);
- */
- // getimage(aster_pic[0],128,0,ROCK_LG_SIZE);
- // getimage(med_aster_pic[0],128,0,ROCK_MD_SIZE);
- // getimage(small_aster_pic[0],128,0,ROCK_SM_SIZE);
- // getimage(bullet_pic[0],500,500,BUL_SIZE);
-
- // getch();
-
- cleardevice();
-
- for (i = 0; i < NUMSTARS; i++)
- {
- star[i].y = random(MAX_WIN_Y-MIN_WIN_Y)+MIN_WIN_Y;
- star[i].x = random(MAX_WIN_X-MIN_WIN_X)+MIN_WIN_X;
- star[i].col = random(15);
- // outport(0x3CD,star[i].y>>6);
- SetWriteBank(star[i].y>>6)
- putpixel(star[i].x,star[i].y,star[i].col);
- }
-
- regs.x.ax = 0x1012;
- regs.x.bx = 0;
- regs.x.cx = 255;
- regs.x.dx = FP_OFF( (int far *)&pal[0] );
- sregs.es = FP_SEG( (int far *)&pal[0] );
- int86x(0x10, ®s, ®s, &sregs);
-
- /*
- setcolor(31);
- bar(50,100,250,150);
-
- setcolor(14);
- bar(600,100,700,200);
- putimage(ship_noshld_pic[0],610,110,SHIP_SIZE);
-
- setcolor(14);
- bar(600,200,700,300);
- putimage(ship_noshld_pic[0],610,210,SHIP_SIZE);
- // putimage(ship_noshld_pic[0],610,210,SHIP_SIZE);
- eraseimage(ship_noshld_pic[0],610,210,SHIP_SIZE);
-
- out[0] = 'a';
- for (i = 0; (i < 250) && (out[0] != 'q'); i+=1)
- {
- putimage(ship_noshld_pic[i%16],i,i,SHIP_SIZE);
- delay(25);
- // putimage(ship_noshld_pic[i%16],i,i,SHIP_SIZE);
- eraseimage(ship_noshld_pic[i%16],i,i,SHIP_SIZE);
-
- if (kbhit())
- out[0] = getch();
-
- // putimage(ship_noshld_pic[i%16],i,i,SHIP_SIZE);
- // getch();
- // eraseimage(ship_noshld_pic[i%16],i,i,SHIP_SIZE);
- // out[0] = getch();
- }
-
- getch();
- exit(0);
-
- cleardevice();
- */
- return;
- }
-
- int display_raw(int x, int y, char *filename, int xsize, int ysize)
- {
- int i, j;
- int ylim = y + ysize, xlim = x + xsize;
- unsigned char color;
- FILE *infile;
-
- // ylim = y + SHIP_SIZE*4;
- // xlim = x + SHIP_SIZE*10;
-
- if ((infile = fopen(filename,"rb")) == NULL)
- // if ((infile = open(filename,O_RDONLY|O_BINARY)) == NULL)
- {
- printf("*ERROR* loading: %s\n",filename);
- return(1);
- }
-
- SetWriteBank(y >> 6);
- for (j = y; j < ylim; j++)
- {
- if ((j & 63) == 0)
- SetWriteBank(j>>6);
- for (i = x; i < xlim; i++)
- {
- color = getc(infile);
- if (color == 192)
- color = 0;
- // outport(0x3CD,j >> 6);
- // SetWriteBank(j>>6);
- putpixel(i,j,color);
- }
- }
-
- fclose(infile);
-
- return(0);
- }
-
- void loadpics(void)
- {
- unsigned int i,j;
- unsigned char ch;
-
- int num;
-
- unsigned char black_pal[768];
-
- FILE *pal_file;
-
- regs.x.ax = 0x38;
- int86(0x10,®s,®s);
-
- // if ((pal_file = fopen("ast_all.pal","rb")) == NULL)
- if ((pal_file = fopen("fil011.dat","rb")) == NULL)
- {
- printf("*ERROR* loading palette!\n");
- exit(1);
- }
-
- for (i = 0; i < 768; i++)
- pal[i] = getc(pal_file);
-
- fclose(pal_file);
-
- for (num = 1; num < 6; num++)
- {
- pal[num*3 ] = 63;
- pal[num*3+1] = num*12;
- pal[num*3+2] = 0;
- }
- for (num = 6; num < 11; num++)
- {
- pal[num*3 ] = 63 - (num-5)*12;
- pal[num*3+1] = 63;
- pal[num*3+2] = 0;
- }
-
- pal[11*3 ] = 10;
- pal[11*3+1] = 63;
- pal[11*3+2] = 10;
-
- pal[12*3 ] = 20;
- pal[12*3+1] = 20;
- pal[12*3+2] = 20;
-
- pal[13*3 ] = 35;
- pal[13*3+1] = 35;
- pal[13*3+2] = 35;
-
- pal[14*3 ] = 0;
- pal[14*3+1] = 30;
- pal[14*3+2] = 0;
-
- for (i = 0; i < 768; i++)
- black_pal[i] = 0;
-
- regs.x.ax = 0x1012;
- regs.x.bx = 0;
- regs.x.cx = 255;
-
- regs.x.dx = FP_OFF( (int far *)&black_pal[0] );
- sregs.es = FP_SEG( (int far *)&black_pal[0] );
-
- // regs.x.dx = FP_OFF( (int far *)&pal[0] );
- // sregs.es = FP_SEG( (int far *)&pal[0] );
-
- int86x(0x10, ®s, ®s, &sregs);
-
- // display_raw(0,0,"shipall.raw",SHIP_SIZE*10,SHIP_SIZE*4);
- display_raw(0,0,"fil006.dat",SHIP_SIZE*10,SHIP_SIZE*4);
- // display_raw(0,SHIP_SIZE*4,"starall.raw",BUL_SIZE*10,BUL_SIZE*3);
- display_raw(0,SHIP_SIZE*4,"fil007.dat",BUL_SIZE*10,BUL_SIZE*3);
- // display_raw(0,SHIP_SIZE*4+BUL_SIZE*3,"ast_all.raw",ROCK_LG_SIZE*10,ROCK_LG_SIZE*5);
- display_raw(0,SHIP_SIZE*4+BUL_SIZE*3,"fil008.dat",ROCK_LG_SIZE*10,ROCK_LG_SIZE*5);
- // display_raw(SHIP_SIZE*10,0,"ast_all2.raw",ROCK_MD_SIZE*10,ROCK_MD_SIZE*5);
- display_raw(SHIP_SIZE*10,0,"fil009.dat",ROCK_MD_SIZE*10,ROCK_MD_SIZE*5);
- // display_raw(SHIP_SIZE*10,ROCK_MD_SIZE*5,"ast_all3.raw",ROCK_SM_SIZE*10,ROCK_SM_SIZE*5);
- display_raw(SHIP_SIZE*10,ROCK_MD_SIZE*5,"fil010.dat",ROCK_SM_SIZE*10,ROCK_SM_SIZE*5);
-
- // for (i = 0; i < 1024; i++)
- // for (j = 512; j < 516; j++)
- // putpixel(i,j,i>>2);
-
- // getch();
- fcloseall();
- }
-
- void getimage(void far *pic_ptr, int x, int y, int size)
- {
- char loopx, loopx_start = size >> 2;
- char loopy, loopy_start = size;
- // char bank = (y>>6)<<4, next_bank = 64 - (y&63);
- char bank = (y>>6), next_bank = 64 - (y&63);
- char far *vid_ptr = (char far *) 0xA0000000 + x + (y << 10);
- int add_to_vid_ptr = 1024 - size;
-
- // outportb(0x3CD,bank);
- SetReadBank(bank);
-
- for (loopy = loopy_start; loopy > 0; loopy--)
- {
- if (next_bank-- == 0)
- {
- bank++;
- // outportb(0x3CD,bank);
- SetReadBank(bank);
- next_bank = 63;
- }
- for (loopx = loopx_start; loopx > 0; loopx--)
- *((long *)((long *)pic_ptr)++) = *((long *)((long *)vid_ptr)++);
- vid_ptr += add_to_vid_ptr;
- }
- return;
- }
-
- void putimage(void far *pic_ptr, int x, int y, int size)
- {
- char loopx, loopx_start = size >> 2;
- char loopy, loopy_start = size;
- char bank = (y>>6)/*+((y>>2)&0xF0)*/, next_bank = 64 - (y & 63);
- char far *vid_ptr = (char far *) 0xA0000000 + x + (y << 10);
- int add_to_vid_ptr = 1024 - size;
-
- // outportb(0x3CD,bank);
- SetWriteBank(bank);
-
- for (loopy = loopy_start; loopy > 0; loopy--)
- {
- if (next_bank-- == 0)
- {
- // bank += 0x11;
- // bank++;
- // outportb(0x3CD,++bank);
- SetWriteBank(++bank);
- next_bank = 63;
- }
- for (loopx = loopx_start; loopx > 0; loopx--)
- {
- if (*((long *)((long *)pic_ptr)) != 0)
- *((long *)((long *)vid_ptr)++) = *((long *)((long *)pic_ptr)++);
- else
- {
- (long *)((long *)vid_ptr)++;
- (long *)((long *)pic_ptr)++;
- }
- }
- vid_ptr += add_to_vid_ptr;
- }
- }
-
- void eraseimage(void far *pic_ptr, int x, int y, int size)
- {
- char loopx, loopx_start = size >> 2;
- char loopy, loopy_start = size;
- char bank = y >> 6, next_bank = 64 - (y & 63);
- char far *vid_ptr = (char far *) 0xA0000000 + x + (y << 10);
- int add_to_vid_ptr = 1024 - size;
-
- // outportb(0x3CD,bank);
- SetWriteBank(bank);
-
- for (loopy = loopy_start; loopy > 0; loopy--)
- {
- if (next_bank-- == 0)
- {
- // outportb(0x3CD,++bank);
- SetWriteBank(++bank);
- next_bank = 63;
- }
- for (loopx = loopx_start; loopx > 0; loopx--)
- {
- if (*((long *)((long *)pic_ptr)) != 0)
- {
- *((long *)((long *)vid_ptr)++) = 0;
- (long *)((long *)pic_ptr)++;
- }
- else
- {
- (long *)((long *)vid_ptr)++;
- (long *)((long *)pic_ptr)++;
- }
- }
- vid_ptr += add_to_vid_ptr;
- }
- }
-
- void putpixel2(int x, int y, long color)
- {
- static long far *ptr = (long far *) 0xA0000000; /* START VID MEM */
-
- // outportb(0x3CD,y>>6);
- SetWriteBank(y>>6);
-
- *((long *)((long *)ptr+(long)x+(long)(y<<10))) = (long)color; /* Write directly to mem */
-
- return;
- }
-
- long getpixel2(int x, int y)
- {
- long temp;
- // long far *ptr = (long far *) 0xA0000000; /* START VID MEM */
-
- // outportb(0x3CD,((y>>6)<<4));
- SetReadBank(y>>6);
-
- temp = *((long far *)((long far *)(0xA0000000)+(long)(x>>2)+(long)(y<<8)));
-
- return(temp);
- }
-
- int initVesa(void)
- {
- long testmode;
- struct VESAINFO
- {
- unsigned char tag[4];
- unsigned int version;
- char far *oem_ptr;
- unsigned long capabilities;
- int far *modes_ptr;
- unsigned int mem64blocks;
-
- char wasted[242];
- } info;
-
- struct MODEINFO
- {
- unsigned int attrib;
- unsigned char wina, winb;
- unsigned int grain, size, winaseg, winbseg;
- void far *bankfunc;
- unsigned int bytes_per_row,xres,yres;
- unsigned char xchar, ychar, bitplanes, bppixel, numbanks, memmodel,
- banksize, pages, reserved, redmask, redpos, greenmask,
- greenpos, bluemask, bluepos, rsvdmask, rsvdpos, dcinfo;
- char wasted[216];
- } mode;
-
- regs.h.ah = 0x4F;
- regs.h.al = 0x00;
- regs.x.di = FP_OFF( (int far *)&info );
- sregs.es = FP_SEG( (int far *)&info );
- int86x(0x10, ®s, ®s, &sregs);
-
- if (info.tag[0] != 'V' || info.tag[1] != 'E' ||
- info.tag[2] != 'S' || info.tag[3] != 'A')
- return(1);
-
- testmode = 1;
- while (*info.modes_ptr != -1 && testmode != 0x105)
- testmode = *info.modes_ptr++;
-
- if (testmode == 1)
- return(1);
-
- if (info.mem64blocks < 16)
- return(1);
-
- regs.x.ax = 0x4F01;
- regs.x.cx = 0x105;
- regs.x.di = FP_OFF( (int far *)&mode );
- sregs.es = FP_SEG( (int far *)&mode );
- int86x(0x10,®s,®s,&sregs);
-
- if (mode.attrib & 1 != 1)
- return(1);
-
- if ( (mode.wina&2) >> 1 == 1)
- ReadWin = 0;
- else if ( (mode.winb&2) >> 1 == 1)
- ReadWin = 1;
- else
- return(1);
-
- if ( (mode.wina&4) >> 2 == 1)
- WriteWin = 0;
- else if ( (mode.winb&4) >> 2 == 1)
- WriteWin = 1;
- else
- return(1);
-
- if (mode.grain != 64)
- return(1);
-
- regs.x.ax = 0x4F02;
- regs.x.bx = 0x0105;
- int86(0x10,®s,®s);
-
- return(0);
- }
-
- void cleardevice(void)
- {
- static int ati_mode_test;
- static int first_time = 0;
-
- if (first_time == 0)
- {
- if (graphics_chip == ATI)
- {
- printf("\nHi there! I see you have selected the ATI graphics chip.");
- printf("\nThat's wonderfull, but unfortunately, I have no clue what");
- printf("\nmode to set it to. Actually, I _do_ have a clue, but");
- printf("\nI have two conflicting sources. So, please select either");
- printf("\nmode 0x64 (hex, 100 decimal) or mode 0x65 (101 decimal).");
- printf("\nActually, try 101 first. :)");
- printf("\nThanks. :)");
- printf("\nBTW - I wouldn't suggest trying *anything* other than these two. :)");
- printf("\n\nWell? What'll it be? 100? or 101? -> ");
- scanf("%d",&ati_mode_test);
- }
- else if (graphics_chip == VESA)
- {
- if (initVesa() == 1)
- {
- printf("ERROR initializing VESA graphics. Exiting...\n");
- exit(1);
- }
- }
- }
-
- if (first_time == 0)
- printf("\nSetting graphics mode...");
-
- if (graphics_chip == TSENG)
- regs.x.ax = 0x38;
- else if (graphics_chip == TRIDENT)
- regs.x.ax = 0x62;
- else if (graphics_chip == ATI)
- // regs.x.ax = 0x65;
- regs.x.ax = ati_mode_test;
- else if (graphics_chip == VESA)
- {
- regs.x.ax = 0x4F02;
- regs.x.bx = 0x0105;
- }
- int86(0x10,®s,®s);
-
- // if (first_time == 0)
- // printf("\nGraphics mode set: Setting SVGA card-specific registers.");
-
- if (graphics_chip == TRIDENT)
- {
- outportb(0x3C4,0x0B);
- outportb(0x3C5,0x00);
- inportb(0x3C5);
- }
- else if (graphics_chip == ATI)
- {
- ati_index = *((int far *)0xC0000010);
- outportb(ati_index,0xBE);
- outportb(ati_index,(inportb(ati_index)) | 0x8 );
- }
-
- // if (first_time == 0)
- // printf("\nIf this is still in text mode, than you are hosed.");
-
- first_time = 1;
- return;
- }
-
- void Init_Sound(void)
- {
- int i;
- if (sound_mode == on)
- {
- i = 0;
- drawscreen();
- // soundb[i++] = loadsound("explode.voc");
- soundb[i++] = loadsound("fil001.dat");
- drawscreen();
- // soundb[i++] = loadsound("blasto.voc");
- soundb[i++] = loadsound("fil002.dat");
- drawscreen();
- // soundb[i++] = loadsound("exp1.voc");
- soundb[i++] = loadsound("fil003.dat");
- drawscreen();
- // soundb[i++] = loadsound("gm-ovr2.voc");
- soundb[i++] = loadsound("fil004.dat");
- drawscreen();
- // soundb[i++] = loadsound("enough.voc");
- soundb[i++] = loadsound("fil005.dat");
- drawscreen();
-
- SB_Setup();
- SB_SetVect(sample);
- }
- return;
- }
-
- void De_Init_Graphics(void)
- {
- int i;
-
- for (i = 0; i < NUM_SHIP_PICS; i++)
- {
- free(ship_noshld_pic[i]);
- free(ship_shld_pic[i]);
- }
- for (i = 0; i < NUM_ROCK_PICS; i++)
- {
- free(aster_pic[i]);
- free(med_aster_pic[i]);
- free(small_aster_pic[i]);
- }
- for (i = 0; i < NUM_BUL_PICS; i++)
- free(bullet_pic[i]);
-
- if (graphics_chip == VESA)
- {
- regs.x.ax = 0x4F02;
- regs.x.bx = 0x0003;
- }
- else
- regs.x.ax = 0x0003;
-
- int86(0x10,®s,®s);
- return;
- }
-
- void De_Init_Sound(void)
- {
- int i;
-
- if (sound_mode == on)
- {
- if (player.status == dieing)
- while (voc_mode);
- VocStop();
- VocPlay((char far *)soundb[QUIT]);
- while (voc_mode);
- }
-
- if (sound_mode == on)
- {
- VocStop();
-
- for (i = 0; i < MAXSND; i++)
- free((char huge *)soundb[i]);
-
- VocStop();
-
- SB_RemoveVect();
- }
- return;
- }
-
- void Setup_Key_Interrupt(void)
- {
- return;
- }
-
- void Enable_Key_Interrupt(void)
- {
- int9->p = addr->p;
- addr->p = (char far *) lookkey;
- }
-
- void Disable_Key_Interrupt(void)
- {
- /* Important! This next statement returns keyboard control to the BIOS
- services. You must execute this command to use any of the Turbo C
- input routines! OR ELSE THE COMPUTER WILL LOCK UP!!! */
- addr->p = int9->p;
- }
-
- void interrupt lookkey(void)
- {
- // char keyb = inportb(96);
- // char far *t = (char far *) 1050;
-
- switch (inportb(96)) // Read from keyboard
- {
- case 1 :
- k.esc = PRESSED; break;
-
- // case keyOpt.left_press :
- case 75 :
- k.left = PRESSED; break;
-
- // case keyOpt.left_unpress :
- case 203 :
- k.left = UNPRESSED; break;
-
- // case keyOpt.right_press :
- case 77 :
- k.right = PRESSED; break;
-
- // case keyOpt.right_unpress :
- case 205 :
- k.right = UNPRESSED; break;
-
- // case keyOpt.thrust_press :
- case 72 :
- k.thrust = PRESSED; break;
-
- // case keyOpt.thrust_unpress :
- case 200 :
- k.thrust = UNPRESSED; break;
-
- // case keyOpt.fire_press :
- case 29 :
- k.fire = PRESSED; break;
-
- // case keyOpt.fire_unpress :
- case 157 :
- k.fire = UNPRESSED; break;
-
- // case keyOpt.shield_press :
- case 42 :
- k.shield = PRESSED;
- break;
-
- // case keyOpt.shield_unpress :
- case 170 :
- k.shield = UNPRESSED; break;
-
-
- // F4 pauses for now.
- case 62 :
- // exit(0); break;
- k.pause = PRESSED; break;
- case 190 :
- // exit(0); break;
- k.pause = UNPRESSED; break;
-
- /* For some reason, once bios discovers the 5 key on the key pad is press
- and numlock is not on, the system locks up. So I put another key code
- (57 = space) into the place where the 5 key code (76) is. */
- /*
- case 76 :
- k.mid = PRESSED;
- outport(96,57);
- break;
- case 204 :
- k.mid = UNPRESSED;
- break;
- */
- }
-
- outportb(0x20,0x20);
-
- return;
- }
-
- char huge *loadsound(char *filename)
- {
- int file;
- WORD ret,rate;
- struct stat mystat;
- long length;
- char huge *base,huge *base2;
-
- stat(filename,&mystat);
- length=mystat.st_size;
- // base=farmalloc(length);
- base=malloc(length);
- if(!base)
- {
- printf("Not enough memory for: %s\n",filename);
- return(NULL);
- }
- file=open(filename,O_RDONLY|O_BINARY);
- if(file== -1)
- {
- printf("Cannot open file: %s\n",filename);
- if(base)
- // farfree(base);
- free(base);
- return(NULL);
- }
- base2=base;
- do
- {
- // do not use this call in small model!
- ret=read(file,base2,32700);
- base2+=ret;
- } while(ret==32700);
- close(file);
- return(base);
- }